import 'package:source_gen/source_gen.dart';
import 'package:xanno/src/anno/utils/log.dart';

class ParsParams {
  static Map<String, dynamic> pars(
      ConstantReader annotation, Map<String, dynamic> params) {
    final map = Map<String, dynamic>();
    params.forEach((key, value) {
      map[key] = value;
      try {
        if (value is bool) {
          map[key] = annotation.read(key).boolValue;
        } else if (value is String) {
          map[key] = annotation.read(key).stringValue;
        } else if (value is List) {
          map[key] = annotation
              .read(key)
              .listValue
              .map((e) => e.toStringValue()!)
              .toList();
        }
      } catch (e) {
        logPrint(e, level: Level.error);
      }
    });
    return map;
  }
}
